import { Toast } from 'mint-ui'
import Router from 'vue-router'
import axios from 'axios'
import config from '../config'
let route = new Router()

let resCode = {
  6006: {
    desc: '登录失效，请重新登录',
    actions: () => {
      route.push('/login')
    }
  },
  6007: {
    desc: '',
    actions: () => {
      let localStorage = window.localStorage
      axios({
        method: 'get',
        headers: {'Authorization': localStorage.getItem('token')},
        url: config.host + "/api/usr/refreshToken"
      }).then(function (data) {
        if (data.data.data.token) {
          localStorage.setItem("token",data.data.data.token)
        } else {
          route.push('/login')
        }
      })
    }
  },
  6029: {
    desc: '实验策略名称重复',
    actions: () => {

    }
  }
}

export default {
  tokenValidate: (code) => {
    switch (code) {
      case 6006:
        resCode[code].actions()
      break
      case 6007:
        resCode[code].actions()
      case 6029:
        resCode[code].actions()
    }
  }
}
